<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="父ID工艺" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'fid', validatorRules.fid]" placeholder="请输入父ID工艺"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="父工艺名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'fname', validatorRules.fname]" placeholder="请输入父工艺名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="标准工时" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'normalHours', validatorRules.normalHours]" placeholder="请输入标准工时"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="是否采集条码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['collectionCode', validatorRules.collectionCode]" :trigger-change="true" dictCode="caiji" placeholder="请选择是否采集条码"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="条码采集类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['collectionTypes', validatorRules.collectionTypes]" :trigger-change="true" dictCode="caijilx" placeholder="请选择条码采集类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="返回工站" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'workstation', validatorRules.workstation]" placeholder="请输入返回工站"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工站地址编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['addressCode', validatorRules.addressCode]" :trigger-change="true" dictCode="address" placeholder="请选择工站地址编码"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工站编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workstationcode', validatorRules.workstationcode]" placeholder="请输入工站编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工站名称 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workstationname', validatorRules.workstationname]" placeholder="请输入工站名称 "></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesPeMakingModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDictSelectTag,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        fid: {},
        fname: {},
        normalHours: {rules: [{ required: true, message: '请输入标准工时!' }]},
        collectionCode: {rules: [{ required: true, message: '请输入是否采集条码!' }]},
        collectionTypes: {rules: [{ required: true, message: '请输入条码采集类型!' }]},
        workstation: {rules: [{ required: true, message: '请输入返回工站!' }]},
        addressCode: {rules: [{ required: true, message: '请输入工站地址编码!' }]},
        workstationcode: {rules: [{ required: true, message: '请输入工站编码!' }]},
        workstationname: {rules: [{ required: true, message: '请输入工站名称 !' }]},
        },
        url: {
          add: '/mes-craft/auto/mesPeProcessRoute/addMesPeMaking',
          edit: '/mes-craft/auto/mesPeProcessRoute/editMesPeMaking',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','fid','fname','normalHours','collectionCode','collectionTypes','workstation','addressCode','workstationid','workstationcode','workstationname','mesPeProcessRouteId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesPeProcessRouteId'] = this.mainId
                  this.formData['mesPeProcessRouteId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','fid','fname','normalHours','collectionCode','collectionTypes','workstation','addressCode','workstationid','workstationcode','workstationname','mesPeProcessRouteId'))
      },


    }
  }
</script>
